package com.wxzl.community.common.base

import android.os.Bundle
import android.view.ViewGroup
import androidx.core.view.forEach
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding

import com.drake.brv.PageRefreshLayout


/***
 * 使用databinding的activity抽像类
 */
abstract class ActivityBase<VM:ViewModelBase, B : ViewDataBinding> : ActivityVM<VM> () {
    abstract val layoutId: Int
    lateinit var binding: B
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)


    }

    override fun initView() {
        super.initView()
        binding = DataBindingUtil.setContentView(this,layoutId)
    }


    /**
     * 获取页面中的PageRefreshLayout
     */
    override fun findPageRefreshLayout(): PageRefreshLayout?{
        val rootView = binding.root as? ViewGroup
        rootView?.let {
            if (rootView is PageRefreshLayout){
                return rootView
            }

            it.forEach { view ->
                if (view is PageRefreshLayout) {
                    return view
                }
            }
        }
        return null
    }






}
